package com.dunqi.gpm.cangxi.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.dunqi.gpm.cangxi.R;
import com.dunqi.gpm.cangxi.common.base.BaseAct;
import com.dunqi.gpm.cangxi.common.view.ComTitleBar;
import com.dunqi.gpm.cangxi.home.bean.Project;
import com.dunqi.gpm.cangxi.home.fragment.EarlyInfoFragment;
import com.dunqi.gpm.cangxi.home.fragment.HomeFragment;

import butterknife.BindView;

public class AuditRequestActivity extends BaseAct {

    private static final String PROJECT = "project";
    @BindView(R.id.title_bar)
    ComTitleBar titleBar;
    @BindView(R.id.container)
    FrameLayout container;
    private Project project;
    private EarlyInfoFragment fragment;

    @Override
    protected void refreshData(Bundle savedInstanceState) {

    }

    @Override
    protected void initUiAndListener() {
        Intent intent = getIntent();
        if (intent != null) {
            project = (Project) intent.getSerializableExtra(PROJECT);
        }

        if (HomeFragment.homeMenuId == 10) {
            titleBar.setRightText("补充前期");
        } else {
            titleBar.setRightText("");
        }

        //新申请
        titleBar.setOnClickListenerOfRight(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddEarlyActivity.start(getActivity(), project);
            }
        });

        fragment = EarlyInfoFragment.newInstance(project);

        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, fragment)
                .commit();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fragment.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_audit_request;
    }


    public static void start(Context context, Project project) {
        Intent intent = new Intent(context, AuditRequestActivity.class);
        if (project != null) {
            intent.putExtra(PROJECT, project);
        }
        context.startActivity(intent);
    }

}
